<template>
  <div class="all">
    <header>
      <div class="div" @click="back">
        <img src="../../../assets/返回.png" alt="">
        <span class="solid">返回</span>
      </div>
      <div class="div">
        <span>选择归属</span>
      </div>
      <div class="div">
        <span></span>
      </div>
    </header>
    <div @click="clickBox(item)"
         v-for="(item, index) in list" :key="index">
      <div class="box"
           v-if="!item.doctor"
           :class="[selectID === item.USER_ID ? 'select' : '']"
           >
        <div class="box_left">
          <img v-if="item.PHOTO !== '' && item.PHOTO !== undefined && item.PHOTO !== null" :src="item.PHOTO" class="PHOTO" alt="">
          <img v-else src="../../../assets/男医生@2x.png" class="PHOTO" alt="">
          <button class="yijiao" v-if="index==0">个人</button>
          <button class="yijiao" v-else>其他</button>
        </div>
        <div class="box_right">
          <ul>
            <li>
            <span class="name">
              <span style="font-weight: bold;font-size: 15px">{{item.NICK_NAME}}</span>
<!--              <span>|</span>-->
<!--              <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>-->
<!--              <span>|</span>-->
<!--              <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>-->
            </span>
              <!--            <button class="btnXiangQing" @click.stop="doctorInfo(item)">医生详情-->
              <!--              <img src="../../../assets/更多白.png" alt="">-->
              <!--            </button>-->
            </li>
            <li>
              <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>
              <span>&nbsp;|&nbsp;</span>
              <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>
            </li>
            <li>
              <span class="jieShao">{{item.HOSPITAL_NAME}}</span>
              <button class="biaoqian" v-if="item.GRADE">{{item.GRADE}}</button>

            </li>
          </ul>
<!--          <div class="box_rigth_bottom">
            <p>
              <a >接诊率:</a><span>{{item.jiezhenCount}}</span>
              <a >好评率:</a><span>{{item.haopingLv}}</span>
              <a >咨询量:</a><span>{{item.zixunCount}}</span>
            </p>
            <p class="goodAt">
              <a style="display: block">擅长:</a>
              <span>{{item.Goodat}}</span>
            </p>
            <p>
              <a >最快回复:</a>
              <span style="color: #1DA4F2"  v-if="item.min !== undefined && item.min !== null && item.min !== ''">{{item.min}}</span>
              <span v-else style="color: #999999">暂无</span>
              <a >平均回复:</a>
              <span style="color: #1DA4F2" v-if="item.avg !== undefined && item.avg !== null && item.avg !== ''">{{item.avg}}</span>
              <span style="color: #999999" v-else>暂无</span>
            </p>
          </div>-->
        </div>
      </div>
      <div class="box"
           v-if="item.doctor"
           :class="selectID == '' ? 'select' : ''">
        <div class="box_left">
          <img v-if="item.team_icon"
               :src="item.team_icon" class="PHOTO" alt="">
          <img v-else src="../../../assets/男医生@2x.png" class="PHOTO" alt="">
          <button class="tagTuandui">机构</button>
        </div>
        <div class="box_right">
          <ul>
            <li>
            <span class="name">
              {{item.team_name}}
              <a style="font-size: 13px;font-weight: 500">（{{item.count}}人）</a>
            </span>
            </li>
            <li>
              <span >团队长：{{item.NICK_NAME}}</span>
              &nbsp;
              &nbsp;
<!--              <span>团队人数：{{item.count}}人</span>-->
              <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>
              <span>&nbsp;|&nbsp;</span>
              <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>
            </li>
<!--            <li>-->
<!--              <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>-->
<!--              <span>|</span>-->
<!--              <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>-->
<!--            </li>-->
            <li>
              <span class="jieShao">{{item.HOSPITAL_NAME}}</span>
              <button class="biaoqian">{{item.GRADE}}</button>
            </li>
          </ul>
<!--          <div class="box_rigth_bottom">
            <p>
              <a >接诊率:</a>
              <span v-if=" item.jiezhenCount!== undefined && item.jiezhenCount!== null && item.jiezhenCount!== ''">{{item.jiezhenCount}}</span>
              <span v-else>暂无</span>
              <a >好评率:</a>
              <span v-if=" item.haopingLv!== undefined && item.haopingLv!== null && item.haopingLv!== ''">{{item.haopingLv}}</span>
              <span v-else>暂无</span>
              <a >咨询量:</a>
              <span v-if=" item.zixunCount!== undefined && item.zixunCount!== null && item.zixunCount!== ''">{{item.zixunCount}}</span>
              <span v-else>暂无</span>
            </p>
            <p class="goodAt">
              <a style="display: block">擅长:</a>
              <span>{{item.team_goodat}}</span>
            </p>
            <p>
              <a >最快回复:</a>
              <span style="color: #1DA4F2"  v-if="item.min !== undefined && item.min !== null && item.min !== ''">{{item.min}}</span>
              <span v-else style="color: #999999">暂无</span>
              <a >平均回复:</a>
              <span style="color: #1DA4F2" v-if="item.avg !== undefined && item.avg !== null && item.avg !== ''">{{item.avg}}</span>
              <span style="color: #999999" v-else>暂无</span>
            </p>
          </div>-->
        </div>
      </div>
    </div>
    <van-loading v-show="isLoading" size="24px" style="width: 100%;height: 80%;
    display:flex;align-items:center;justify-content:center; color: #1da4f2" vertical>
      加载中...
    </van-loading>
  </div>
</template>

<script>
export default {
  name: 'SelectTeamMembers',
  data () {
    return {
      userid: this.$route.query.userid,
      team_id: this.$route.query.team_id,
      team_name: this.$route.query.team_name,
      team_photo: '',
      list: [],
      selectID: null,
      teamData: [],
      isLoading: true
    }
  },
  mounted () {
    if (sessionStorage.getItem('TeamOrganCode')) {
      let data = JSON.parse(sessionStorage.getItem('TeamOrganCode'))
      this.selectID = data.doc_user_id
    }
    this.getTeamDetail()
    this.getDoctorList()
  },
  methods: {
    clickBox (item) {
      let data = new Object()
      if (sessionStorage.getItem('TeamOrganCode')) {
        data = JSON.parse(sessionStorage.getItem('TeamOrganCode'))
      }
      let USER_ID = ''
      let doc_name = ''
      if (item.doctor) {
        // data.doc_user_id = item.id
        data.doc_user_id = ''
        data.group_id = ''
      } else {
        data.doc_user_id = item.USER_ID
        data.group_id = item.group_id
        USER_ID = item.USER_ID
        doc_name = item.NICK_NAME
      }
      sessionStorage.setItem('TeamOrganCode', JSON.stringify(data))
      this.$router.push({path: '/TeamOrganCode',
        query: {userid: this.userid,
          team_id: this.team_id,
          doc_user_id: USER_ID,
          group_id: item.group_id,
          doc_name: doc_name
      }})
    },
    getTeamDetail () {
      this.$http.Teamdetail({id: this.team_id})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            this.team_photo = res.data.data.PHOTO
            this.teamData = res.data.data
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    getDoctorList () {
      this.isLoading = true
      this.$http.findDoctor({team_id: this.team_id})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            // let obj = {
            //   NICK_NAME: this.team_name,
            //   group_id: null,
            //   USER_ID: '',
            //   PHOTO: this.team_photo
            // }
            this.list = res.data.data
            let self = []
            for (let i in this.list) {
              if (this.list[i].USER_ID === this.userid) {
                // this.list.unshift(this.list[i])
                self = this.list[i]
                this.list.splice(i, 1)
                break
              }
            }
            this.list.unshift(self)

            this.list.splice(1, 0, this.teamData)
            console.log(this.list)
            this.isLoading = false
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    }
  }
}
</script>

<style scoped>
.all{
  width: 100%;
  height: 100%;
  background: #FAF9FE;
  overflow: auto;
  font-size: 15px;
  font-family: PingFang SC;
}
header{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #E5E5E5;
  background: white;
  position: sticky;
  top: 0;
  z-index: 9;
}
.div{
  width: 33%;
  height: 100%;
  display: flex;
  align-items: center;
  font-family: "PingFang SC";
  font-size: 15px;
  font-weight: bold;
}
.div img{
  margin-right: 5px;
}
.div:nth-child(1) img{
  height: 13px;
  width: 7px;
  margin-left: 15px;
}
.div:nth-child(3) img{
  margin-right: 5px;
  width: 13px;
  height: 13px;
}
.div:nth-child(3) span{
  margin-right: 15px;
}
.div:nth-child(2){
  justify-content: center;
}
.div:nth-child(3){
  justify-content: flex-end;
}
.solid{
  color: #1DA4F2;
}
.box{
  padding: 10px;
  box-sizing: border-box;
  background: white;
  margin-bottom: 8px;
  display: flex;
}
/*.all .box:last-of-type{*/
/*  margin-bottom: 60px;*/
/*}*/
.PHOTO{
  width: 55px;
  height: 55px;
  border-radius: 50%;
  object-fit: cover;
}
.box_left{
  width: 23%;
  display: flex;
  align-items: center;
  flex-direction: column;
  /*justify-content: space-between;*/
}
.dict_name{
  font-size: 11px;
  border: 1px solid #1DA4F2;
  border-radius: 2px;
  background: rgba(16, 184, 246, 0.1);
  color: #1da4f2;
  padding: 1px 3px;
  box-sizing: border-box;
  white-space: nowrap;
  /*margin-top: 10px;*/
}
.box_right{
  width: 78%;
}
.box_right ul{
  /*height: 60px;*/
  display: flex;
  flex-direction: column;
  align-content: space-around;
  justify-content: space-around;
}
.box_right ul li{
  display: flex;
  align-items: center;
  font-size: 13px;
  font-family: PingFang SC;
  min-height: 25px;
}
.box_right ul li:nth-child(1){
  justify-content: space-between;
}
.name{
  font-size: 15px!important;
  font-weight: bold;
  color: #333333;
}
.biaoqian{
  /*padding: 0px 8px;*/
  min-width: 44px;
  height: 18px;
  border-radius: 15px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  /* background: rgba(29, 164, 242, 0.1); */
  background: transparent;
  color: #1DA4F2;
  /* border: none; */
  border: 1px solid;
  font-size: 11px;
  margin-left: 8px;
}
.btnXiangQing{
  color: white;
  background: #1DA4F2;
  border: none;
  padding: 3px 8px;
  border-radius: 2px;
  box-sizing: border-box;
  font-size: 11px;
}
.btnXiangQing img{
  width: 5px;
  height: 9px;
  margin-left: 5px;
}

.btnXiangQing,
.biaoqian,
.jieShao
{
  display: flex;
  align-items: center;
  justify-content: center;
}
.jieShao{
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: 500;
  color: #333333;
  margin-right: 8px;
}
.box_rigth_bottom{
  margin-top: 5px;
}
.box_rigth_bottom p{
  margin-bottom: 5px;
}
.box_rigth_bottom p:nth-child(1),
.box_rigth_bottom p:nth-child(3){
  font-size: 13px;
}
.box_rigth_bottom p a{
}
.box_rigth_bottom p span{
  color: #E3170D;
  margin: 0 8px 0 3px;
}
.goodAt{
  font-size: 13px;
  display: flex;
}
.goodAt a{
  display: block;
  white-space: nowrap;
}
.goodAt span{
  /*width: 80%;*/
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #333 !important;
}
.select{
  background: rgba(29, 164, 242, 0.2);
}
.tagTuandui,
.yijiao{
  font-size: 11px;
  min-height: 18px;
  padding: 0 8px;
  box-sizing: border-box;
  border-radius: 10px;
  border: none;
}
.yijiao{
  background: #1da4f2;
  color: #FFFFFF;
}
.tagTuandui{
  background: linear-gradient(90deg, #F9BD77, #FFED91);
  color: #A8610B;
}
</style>
